<?php

namespace app\models;

use app\traits\ModelTrait;

class Tag extends \Phalcon\Mvc\Model
{
    use ModelTrait;

    const TABLE = 'tag';

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=10, nullable=false)
     */
    public $id;

    /**
     *
     * @var string
     * @Column(type="string", length=30, nullable=false)
     */
    public $title;

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return self::TABLE;
    }

    /**
     * @param $tags 由,分隔的tag字符串 返回一个去除重复值的tag数组
     * @return array
     */
    public static function normalTags($tags)
    {
        if (empty($tags)) {
            return [];
        }
        $tags = explode(',', $tags);
        return array_unique($tags);
    }

}
